package org.nf.partner.service.impl;

import org.nf.partner.dao.PartnerDAO;
import org.nf.partner.dao.impl.PartnerDaoImpl;
import org.nf.partner.model.Partner;
import org.nf.partner.service.PartnerService;
import org.nf.product.model.Product;
import org.nf.product.util.PageUtils;
import org.nf.product.vo.PageVO;

import java.util.List;

public class PartnerServiceImpl implements PartnerService {
    private PartnerDAO partnerDAO =  new PartnerDaoImpl();

    /**
     * 添加合作商
     * @param partner
     * @return
     */
    @Override
    public int insertPartner(Partner partner) {

        return partnerDAO.insertPartner(partner);
    }

    /**
     * 根据名字查询
     * @param partnerName
     * @return
     */
    @Override
    public List<Partner> selectPartnerName(String partnerName) {
        return partnerDAO.selectPartnerName(partnerName);
    }

    /**
     * 查询全部
     * @param partner
     * @return
     */
    @Override
    public List<Partner> listPartner(Partner partner) {
        return partnerDAO.listPartner(partner);
    }

    /**
     * 分页查询
     * @param page 第几页
     * @param limit 查多少条
     * @return
     */
    @Override
    public PageVO<List<Partner>> listPartnerPage(int page, int limit) {
        Partner partner = new Partner();
        //先根据page计算出从表的第几条开始查询
        int numberOf = PageUtils.toNumberOf(page, limit);
        //创建DAO实例
        PartnerDAO dao = new PartnerDaoImpl();
        List<Partner> list =dao.listPartnerPage(partner,page,limit);
        Long count = dao.countPartner();
        return PageUtils.toPageVO(list,count);
    }
}
